

# 读  read
# file = open(r"C:\TT\习知\12\my_test_demo_12\异常等内容\my_test_demo.txt", "r", encoding="utf-8")  # 读取文件内包含中文及中文字符时，编码格式需设置为utf-8
# datas = file.read()     # 读取所有数据
# datas = file.readline()     # 读取一行数据，指针移动
# print(datas)
# print(file.tell())          # 中文占3个指针位置，英文占一个
# datas2 = file.readline()    # 从指针位置往后读取一行，指针移动
# print(datas2)
# print(file.tell())
# print(file.mode,file.name)  # 获取文件打开模式及文件名参数

# line_1 = file.readline()
# print(line_1)
# file.seek(7)    # 设置指针位置
# line_2 = file.readline()
# print(line_2)


# # 写  w是覆盖，a追加
# file = open(r"C:\TT\习知\12\my_test_demo_12\异常等内容\my_test_demo.txt", "a", encoding="utf-8")  # 写文件包含中文及中文字符时，编码格式需设置为utf-8
# line_1 = "锄禾日当午，\n"
# line_2 = "锄禾日当午，\n"
# line_3 = "锄禾日当午，\n"
# line_4 = "锄禾日当午，\n"
# file.write(line_1)
# file.write(line_2)
# file.write(line_3)
# file.write(line_4)


# 二进制模式 b
file_1 = open("img.png", "rb")
datas = file_1.read()
file_2 = open("new_img.png", "wb")
file_2.write(datas)
